package ModelLag;
import java.util.Date;

/**
 * The Loan class creates an object of the type Loan.
 * 
 * @author (Lackshan, Mikkel, Nick, patrick, Simon, Yousef) 
 * @project (Tema design)
 * @version (2014.11.05)
 */
public class Loan
{
    private Date loanDate;
    private Date returnDate;
    private Person person;
    private Copy copy;

    /**
     * Constructor for objects of class Loan
     */
    public Loan(Person person, Date loneDate, Date returnDate, Copy copy){
        this.person = person;
        this.loanDate = loneDate;
        this.returnDate = returnDate;
        this.copy = copy; 
        // set state of copy to true
        copy.setState(true);
    }
    
    /**
     * Sets the loanDate for the Loan.
     * 
     * @param l is the user input for the loanDate of a Loan.
     */
    public void setLoanDate(Date l){
        loanDate = l;
    }
    
    /**
     * Sets the returnDate for the Loan.
     * 
     * @param r is the user input for the returnDate of a Loan.
     */
    public void setReturnDate(Date r){
        returnDate = r;
    }
    
    /**
     * Get Person Object
     * 
     * @return Person Object
     */
    public Person GetPerson(){
        return person;        
    }
    
     /**
     * Get Copy Object
     * 
     * @return Copy Object
     */
    public Copy GetCopy(){
        return copy;        
    }
    
    /**
     * Returns the loanDate for the Loan.
     * 
     * @param returns the loanDate of the Loan
     */
    public Date getLoanDate(){
        return loanDate;
    }
    
    /**
     * Returns the returnDate for the Loan.
     * 
     * @param returns the returnDate of the Loan
     */
    public Date getReturnDate(){
        return returnDate;
    }
    
    /**
     * Set's the sate of the copy to false, when returned
     * 
     */
    public void endLoan(){
        copy.setState(false);
    }
    
    /**
     * Check wether the actual return date of the loan is past the return date of the loan
     * 
     * @return true if the copy was returned on time
     */
    public boolean returnedOntime(){
        Date currentDate = new Date();
        return !currentDate.after(returnDate);
    }
}
